diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-24 20:00:08 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-27 14:47:51 +0100 |
| commit | f111685c5886f3e77edfd3621c98d8ac1b9bcce4 (patch) | |
| tree | 62a541fe3afeb64bf745443706fbfb02e96c5230 /src/pages/thematique/[slug].tsx | |
| parent | bee515641cb144be9a855ff2cac258d2fedab21d (diff) | |
refactor(services, types): reorganize GraphQL fetchers and data types
The Typescript mapped types was useful for autocompletion in fetchers
but their are harder to maintain. I think it's better to keep each
query close to its fetcher to have a better understanding of the
fetched data. So I:
* colocate queries with their own fetcher
* colocate mutations with their own mutator
* remove Typescript mapped types for queries and mutations
* move data convertors inside graphql services
* rename most of data types and fetchers
Diffstat (limited to 'src/pages/thematique/[slug].tsx')
| -rw-r--r-- | src/pages/thematique/[slug].tsx | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx index b8518c5..a44c98b 100644 --- a/src/pages/thematique/[slug].tsx +++ b/src/pages/thematique/[slug].tsx @@ -17,10 +17,11 @@ import { PageBody, } from '../../components'; import { - getAllThematicsSlugs, - getThematicBySlug, - getThematicsPreview, - getTotalThematics, + convertTaxonomyToPageLink, + fetchAllThematicsSlugs, + fetchThematic, + fetchThematicsCount, + fetchThematicsList, } from '../../services/graphql'; import styles from '../../styles/pages/blog.module.scss'; import type { NextPageWithLayout, PageLink, Thematic } from '../../types'; @@ -28,7 +29,6 @@ import { CONFIG } from '../../utils/config'; import { ROUTES } from '../../utils/constants'; import { getLinksItemData, - getPageLinkFromRawData, getPostsWithUrl, getSchemaJson, getSinglePageSchema, @@ -191,15 +191,13 @@ export const getStaticProps: GetStaticProps<ThematicPageProps> = async ({ locale, params, }) => { - const currentThematic = await getThematicBySlug( - (params as ThematicParams).slug - ); - const totalThematics = await getTotalThematics(); - const allThematicsEdges = await getThematicsPreview({ + const currentThematic = await fetchThematic((params as ThematicParams).slug); + const totalThematics = await fetchThematicsCount(); + const allThematicsEdges = await fetchThematicsList({ first: totalThematics, }); const allThematics = allThematicsEdges.edges.map((edge) => - getPageLinkFromRawData(edge.node, 'thematic') + convertTaxonomyToPageLink(edge.node) ); const allThematicsLinks = allThematics.filter( (thematic) => @@ -218,7 +216,7 @@ export const getStaticProps: GetStaticProps<ThematicPageProps> = async ({ }; export const getStaticPaths: GetStaticPaths = async () => { - const slugs = await getAllThematicsSlugs(); + const slugs = await fetchAllThematicsSlugs(); const paths = slugs.map((slug) => { return { params: { slug } }; }); |
